package com.easyaop.api.aopalliance;

import com.easyaop.api.around.Call;
import com.easyaop.api.join.JoinPoint;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;

/**
 * @Description :
 * @Create on : 2025/5/13 09:48
 * @author albert
 **/
public class DefaultMethodInvocation implements MethodInvocation {
    private Object target;
    private Object[] args;
    private JoinPoint joinPoint;
    private Call call;

    DefaultMethodInvocation(Object target, Object[] args, JoinPoint joinPoint, Call call){
        this.target = target;
        this.args = args;
        this.joinPoint = joinPoint;
        this.call = call;
    }

    @Override
    public Method getMethod() {
        return this.joinPoint.getJavaMethod();
    }

    @Override
    public Object[] getArguments() {
        return this.args;
    }

    @Override
    public Object proceed() throws Throwable {
        return this.call.call();
    }

    @Override
    public Object getThis() {
        return this.target;
    }

    @Override
    public AccessibleObject getStaticPart() {
        return this.joinPoint.getJavaMethod();
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    public Object[] getArgs() {
        return args;
    }

    public void setArgs(Object[] args) {
        this.args = args;
    }

    public JoinPoint getJoinPoint() {
        return joinPoint;
    }

    public void setJoinPoint(JoinPoint joinPoint) {
        this.joinPoint = joinPoint;
    }

    public Call getCall() {
        return call;
    }

    public void setCall(Call call) {
        this.call = call;
    }
}
